import React, { Component, PropTypes } from 'react'

//let { LinkedStateMixin } = React.addons;

import './../css/default-text.css'
class TextInput extends Component {

	constructor (props, context) {
	    super(props, context);
	    this.state = {
            message: this.props.val
		}; // 初始化状态
	}

	componentWillReceiveProps(nextProps){//除手动输入之外的方式改变val
        // console.log(nextProps.disabled)
		if(nextProps.val){
			this.setState({
				message : nextProps.val
			})
		}
	}

	handleChange(e){
		var message = e.target.value;
		this.setState({message: message});
		this.props.onChange(message);
	}

	render() {
		const {placeHolder,inputId, textClass, style, type} = this.props;
		var message = this.state.message;

		return (
			<input disabled={this.props.disabled} ref={this} style={style} type={type ? type : "text" }
                   placeholder={placeHolder} id={inputId} value={message} className={textClass ? textClass : "default-text"}
                   onChange={this.handleChange.bind(this)}/>
		)
	}
}

TextInput.propTypes = {
	onChange: PropTypes.func.isRequired,
	// val : PropTypes.string.isRequired
};

export default TextInput
